﻿/********************************************************************************************************************
* Author:	Christos Polydorou																						*
* Email:	std04237@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_searchentities" that searches for		*
*			entities.																								*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_searchEntities]
	@userid bigint,
	@entityname nvarchar(50)
AS
	DECLARE @categoryids table ( catid bigint )

	INSERT INTO @categoryids
	EXEC usp_getcategorieswithaccess @usrid = @userid

	SELECT Entities.ID,Entities.Category,Entities.Name
	FROM entities, categories, @categoryids
	WHERE Categories.ID = catid and Entities.Category = Categories.ID and Entities.Name like @entityname

RETURN 0